#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.contrib.syndication.feeds import Feed
from django.utils.feedgenerator import Atom1Feed
from weblog.models import Post
from django.conf import settings
import datetime

class RssLatestPosts(Feed):
    """ Rss of latest posts
        Posts num set by the settings.py with the var "FEED_COUNT"
    """ 
    title_template = 'feeds/title.html'
    description_template = 'feeds/description.html'
    title = settings.SITE_TITLE 
    link = settings.SITE_URL 
    description = settings.TAG_LINE 

    def items(self):
        return Post.objects.filter(type='post').order_by('-date')[:settings.FEED_COUNT] 

    def item_link(self, item):
        return settings.SITE_URL + item.date.strftime("%y/%m/") + str(item.id)
    
    def item_pubdate(self, item):
        return item.date
        #return datetime.datetime(item.date.year, item.date.month, item.date.day)


class AtomLatestPosts(RssLatestPosts):
    feed_type = Atom1Feed
    subtitle = RssLatestPosts.description
